package Practice1_Collection.P12_Iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

public class NormalList<T> implements Iterable<T> {

    private List<T> list = new ArrayList<>();

    public void add(T t) {
        list.add(t);
    }

    @Override
    public Iterator<T> iterator() {
        return new NormalIterator(0);
    }

    class NormalIterator implements Iterator<T> {
        int index;
        int lastRet = -1;

        @Override
        public boolean hasNext() {
            return index < list.size();
        }

        @Override
        public T next() {
            lastRet = index;
            index++;
            return list.get(lastRet);
        }

        public NormalIterator(int index) {
            this.index = index;
        }
    }
}
